/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ventanas;

import algoritmomemetico.MaquinaBeanData;
import algoritmomemetico.MaquinaBeanFunction;
import algoritmomemetico.AlgMemeticoBeanFunction;
import algoritmomemetico.RendimientoBeanData;
import algoritmomemetico.TrabajadorBeanData;
import algoritmomemetico.TrabajadorBeanFunction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;

/**
 *
 * @author MI PC
 */
public class Menu extends javax.swing.JFrame {

    /**
     * Creates new form Menu
     */
    public Menu() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        TextArea1 = new javax.swing.JTextArea();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        TextArea1.setColumns(20);
        TextArea1.setRows(5);
        jScrollPane1.setViewportView(TextArea1);

        jButton1.setText("Abiri Archivo Maquinas");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Abiri Archivo Trabajador");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Generar Solucion");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(14, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 451, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(24, 24, 24))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 426, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        MaquinaBeanFunction maquinaFuncion= new MaquinaBeanFunction();
        HashMap<String,MaquinaBeanData> maquinas= maquinaFuncion.cargarMaquinas();
        HashMap<Integer,String> tipos=maquinaFuncion.cargarTipoMaquinaH();
        StringBuffer sf= new StringBuffer();
        MaquinaBeanData maquinaData= new MaquinaBeanData();        
        int size=maquinas.size();
        sf.append("**Maquina**\n"
                + "Codigo - Nombre - Tipo - Produccion\n");
        ArrayList<MaquinaBeanData> temp=new ArrayList<>(maquinas.values());
        for(int i=0;i<size;i++){
            maquinaData= temp.get(i);
            sf.append(maquinaData.getCodigo()+" - ");
            sf.append(maquinaData.getNombre()+" - ");
            sf.append(tipos.get(Integer.valueOf(maquinaData.getTipo()))+" - ");
            sf.append(maquinaData.getProduccion()+"\n");
        }
            sf.append("\n");
        TextArea1.setText(sf.toString());
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        
        TrabajadorBeanFunction trabajadorFunction= new TrabajadorBeanFunction();
        MaquinaBeanFunction maquinaFuncion= new MaquinaBeanFunction();
        HashMap<String,TrabajadorBeanData> trabajadores= trabajadorFunction.cargarTrabajadores();
        StringBuffer sf= new StringBuffer();
        sf.append("**Trabajadores**\n");
        HashMap<Integer,String> tipos=maquinaFuncion.cargarTipoMaquinaH();
        ArrayList<TrabajadorBeanData> temp2= new ArrayList<>(trabajadores.values());
        for(int i=0;i<trabajadores.size();i++){
            TrabajadorBeanData temp= temp2.get(i);
            sf.append("Codigo:"+temp.getCodigo()+"\n");
            Vector<RendimientoBeanData> rends=temp.getRendimiento();
            Iterator<RendimientoBeanData> it=null;
            for(it=rends.iterator();it.hasNext();){
                RendimientoBeanData tempR=it.next();
            sf.append("\tTipo Maquina:"+tipos.get(tempR.getCodMaquina())+"\n");
            sf.append("\tAtiende:"+(tempR.getProduccion()*100)+"%\n");
            sf.append("\tDesperdicia:"+(tempR.getPerdida()*100)+"%\n");
            }
        }
        TextArea1.setText(sf.toString());
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        AlgMemeticoBeanFunction prueba= new AlgMemeticoBeanFunction();  
        TrabajadorBeanFunction trabajadorFunction= new TrabajadorBeanFunction();
        MaquinaBeanFunction maquinaFuncion= new MaquinaBeanFunction();
        HashMap<String,TrabajadorBeanData> trabajadores= trabajadorFunction.cargarTrabajadores();
        HashMap<String,MaquinaBeanData> maquinas=maquinaFuncion.cargarMaquinas();
        prueba.setCodTrabajadores(new ArrayList<String>(trabajadores.keySet()));
        prueba.setMaquinasDisponibles(maquinas);
        prueba.setTrabajadores(trabajadores);
        prueba.setCodMaquinas(new ArrayList<String>(maquinas.keySet()));
        try{
            String rsp=prueba.ALG01();
        }
        catch(Exception e){
            TextArea1.setText(e.getMessage());
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Menu().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea TextArea1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
